<?php

namespace App\Repository;

use App\Consts\GlobalConst;
use App\Consts\GlobalReportConst;
use App\Models\SysReport;
use App\Models\SysReportCategory;

/**
 * @package App\Repository
 * @see ReportRepository
 */
class ReportRepository extends BaseRepository
{
    public function getCategoryList($searchParams)
    {
        $provider = SysReportCategory::getInstance()
            ->where('status', GlobalReportConst::CATEGORY_STATUS_NORMAL)
            ->where('is_deleted', GlobalConst::IS_NOT_DELETE);

        if (array_key_exists('is_tort', $searchParams)) {
            $provider->where('is_tort', $searchParams['is_tort']);
        }

        $provider->orderByDesc('weight');

        return $this->setPagination($provider);
    }

    /**
     * 新增举报
     * @param $params
     * @return SysReport|\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|mixed
     */
    public function create($params)
    {
        $report = SysReport::getInstance();
        $load = [
            'category_id' => $params['category_id'],
            'content' => $params['content'] ?? '',
            'target_id' => $params['target_id'],
            'target_type' => $params['target_type'],
            'user_id' => $params['user_id'],
        ];

        return $report->create($load);
    }
}
